<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/common.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
	<span class="layui-breadcrumb">
			<a href="">首页</a>
			<a><cite>用户管理</cite></a>
			<a><cite>指导老师</cite></a>
	</span>
	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
		<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
	</a>
</div>
<div class="layui-fluid">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<div class="layui-card">
				<div class="layui-card-body ">
					<form class="layui-form layui-col-space5 flex" style="display: flex;" @submit.prevent>
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5" style="width: 40px;">账号</div>
							<input type="text" name="accountValue" id="accountValue" placeholder="账号" autocomplete="off" class="layui-input"></div>
						<div class="layui-input-inline layui-show-xs-block">
							<button class="layui-btn" lay-submit="" lay-filter="search">
								<i class="layui-icon">&#xe615;</i></button>
						</div>
					</form>
				</div>
				<div class="layui-card-body" id="content" v-cloak>
					<table class="layui-table layui-form" id="table">
						<span>共计{{total}}条数据</span>
					</table>
					<section id="page"></section>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script src="./js/vue.js"></script>
<script src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/abkj/auth/api/account.js"></script>
<script type="text/javascript" src="./js/abkj/auth/api/userinfo.js"></script>
<script type="text/javascript" src="./js/abkj/auth/api/userinfoview.js"></script>
<script type="text/javascript" src="./js/abkj/ext/login.js"></script>

<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
<script type="text/html" id="operating">
<a href="javascript:;" class="layui-table-link" onclick=app.stop('{{JSON.stringify(d)}}')>{{ d.status === 1 ? '启动' : '禁用' }}</a>
<a href="javascript:;" class="layui-table-link" onclick="delete1('{{d.id}}')")>删除</a>
</script>
<script>
function delete1(id){
	if (confirm("是否删除该指导教师吗?")){
		delAccount(id,function(data){
			alert("删除成功!")
			location.reload()
		})
	}
}
var app=new Vue({
	el: '#content',
	data: {
		listAccount:[],
		listUserInfo:[],
		list:[],
		total: 0,
		pageNo: 1,
		pageSize: 50,
		status:['审核','待审核' ,'通过', '不通过'],
		participate:['审核','参赛' ,'弃权' ],
		cols: [ //表头
    
			{field: 'id', title: '账号ID', width: 110},

			{field: 'account', title: '账号', width: 110},
			{field: 'name', title: '姓名', width: 110},
			{field: 'idCardType', title: '证件', width: 110},
			{field: 'idcard', title: '证件号', width: 110},
			{field: 'gender', title: '性别', width: 110},
			{field: 'job', title: '职务', width: 110},
			{field: 'workUnit', title: '工作单位', width: 110},
			{field: 'email', title: '电子邮箱', width: 135},
			{field: 'createTime', title: '注册时间', width: 110},
			{field: 'operating', title: '操作', width: 135, templet: '#operating'},
		]
	},
	mounted: function () {
		this.getData()
		var vm=this;
		layui.use('form',function(){
			layui.form.on('submit(search)', function (data) {
					if(data.field.accountValue == ''){
							layer.msg("请输入查询帐号", function () {
								return;
							})
						}else{
							console.log(data)
							var that=app
							app.getData1(data.field.accountValue)
							setTimeout(function(){
								var table = layui.table
							 var form = layui.form
							 that.list=that.list.reverse()
							 for (i=0;i<that.list.length;i++){
						   if (that.list[i].gender=='male' || that.list[i].gender=='男'){
								 that.list[i].gender='男'
							 }
							 else{
								 that.list[i].gender='女'
							 }
							}
							 // that.total=that.list.length
							//  alert(JSON.stringify(that.list))
							 //头工具栏事件
							 table.render({
								 elem: '#table',
								 url:'',
								 title: '用户数据表',
								 cols: [that.cols],
								 data: that.list,
								 count:app.listAccount.total,
								 page: true,
								 limit:vm.pageSize
							 })

							},1000)
					}

					// layer.msg(JSON.stringify(data.field), function () {
					// location.href = 'index.html'
					// })
					return false
				})
		})
	},
	methods:{
		opentab:function(name,url){
			//单击事件
			xadmin.add_tab(name,url)
		},
		setAccountState:function(varId,state){
			//state 0 启用 1 禁用
			var obj={
				id:varId,
				isProhibit:state
			}
			AccountupdateById(obj,function(data){
				//修改成功
			},function(status,message){
				//修改失败
			})
		},
		getAccountFromMem:function(varId){
			for(var i=0;i<this.listAccount.length;++i){
				if(this.listAccount[i].id==varId){
					return this.listAccount[i];
				}
			}
		},
		queryByAccount:function(varAccount){
			//帐号查询
			var vm = this
			var queryData = {
				page:{
					current: vm.pageNo, //当前页数
					size: vm.pageSize   //每页长度
				},
				cond:{ //条件
					eq:{ // 多条件对象
						userName:varAccount,
						roleId:3
					}
				}
			};
			this.loadAccount(queryData)
		},
		loadAccount:function(varParam){
			var vm = this
			var idcardReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
			 UserinfoViewqueryList(varParam,function(data){
				  // alert(JSON.stringify(data))
				vm.listUserInfo.records=data;
				var ids=[];

				vm.total = data.total
				vm.list = []
				for(var i=0; i < vm.listUserInfo.records.length; ++i){
					vm.listUserInfo.records[i].index=i+(vm.listUserInfo.current-1)*vm.listUserInfo.size;
					var varAccount = vm.getAccountFromMem(vm.listUserInfo.records[i].id);
					vm.listUserInfo.records[i].account=vm.listUserInfo.records[i].userName;
					// vm.listUserInfo.records[i].createTime=varAccount.createTime;
					vm.listUserInfo.records[i].status= vm.listUserInfo.records[i].isProhibit
					vm.listUserInfo.records[i].idCardType=idcardReg.test(vm.listUserInfo.records[i].idcard)?'身份证':'护照'
					vm.list.push(vm.listUserInfo.records[i])
				}
				vm.init()
				// for(var i=0; i<data.records.length;++i){
				// 	ids.push(data.records[i].id);
				// }
				// var userInfoParam={
				// 	in:{
				// 		data:ids,
				// 		attrName:"id"
				// 	}
				// }
				// AccountqueryList(userInfoParam,function(data){
				// 	vm.listAccount=data;
				// 	vm.list = []
				// 	for(var i=0; i < vm.listUserInfo.records.length; ++i){
				// 		vm.listUserInfo.records[i].index=i+(vm.listUserInfo.current-1)*vm.listUserInfo.size;
				// 		var varAccount = vm.getAccountFromMem(vm.listUserInfo.records[i].id);
				// 		vm.listUserInfo.records[i].account=varAccount.userName;
				// 		vm.listUserInfo.records[i].createTime=varAccount.createTime;
				// 		vm.listUserInfo.records[i].status= varAccount.isProhibit
				// 		vm.list.push(vm.listUserInfo.records[i])
				// 	}
				// 	vm.init()
				// },function(status,message){

				// })

			},function(status,message){

			})

		},
		getData: function () {
			var vm = this
			var queryData = {

					eq:{ // 多条件对象
						roleId:3

				}
			};
			this.loadAccount(queryData);
		},
		getData1: function (account) {
			var vm = this
			var queryData = {


					eq:{ // 多条件对象
						roleId:3
					}

			};
			if (account!=undefined&&account!=null&&account!=''){
				queryData = {
				 //条件
						eq:{ // 多条件对象
							roleId:3,
							userName:account

				   }
					  }
			}


			this.loadAccount(queryData);
		},
		stop: function (data) {
			data = JSON.parse(data)
			console.log(data)
			var reqObj={
				id:data.id,
				isProhibit:data.status === 1?0:1
			}
			var text = data.state === 1 ? '启用' : '禁用'
			// 禁用启用逻辑
			layer.confirm('确定' + text + '吗？', function () {
				// 掉接口

				AccountupdateById(reqObj,function(data){
					layer.msg(text + '成功!', {icon: 1})
				})
			})
		},
		init:function() {
			var that = this
			var vm = this
			layui.use(['form', 'laypage','table'], function () {
				// var laypage = layui.laypage;
				// //执行一个laypage实例
				// laypage.render({
				// 	elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
				// 	,count: 16 //数据总数，从服务端得到
				// });
				var table = layui.table
				var form = layui.form
				that.list=that.list.reverse()
				for (i=0;i<that.list.length;i++){
						   if (that.list[i].gender=='male'  || that.list[i].gender=='男'){
								 that.list[i].gender='男'
							 }
							 else{
								 that.list[i].gender='女'
							 }
							}			 
				that.total=that.list.length
			 // alert(JSON.stringify(that.list))
				//头工具栏事件
				table.render({
					elem: '#table',
					url:'',
					title: '用户数据表',
					cols: [that.cols],
					data: that.list,
					count:app.listAccount.total,
					page: true,
					limit:50
				})

				// layui.laypage.render({
				// 	elem: 'page',
				// 	curr: vm.pageNo,
				// 	count: vm.total,
				// 	jump: function (obj, first) {
				// 		if (first) return
				// 		vm.pageNo = obj.curr
				// 		// vm.getData()
				// 	}
				// })
				// form.on('submit(search)', function (data) {
				// 	console.log(data)
				// 	app.queryByAccount(data.field.accountValue)
				// 	// layer.msg(JSON.stringify(data.field), function () {
				// 	// location.href = 'index.html'
				// 	// })
				// 	return false
				// })
			})
		}
	}
})
</script>

</html>
